package controller;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Invitation;
import service.Invitationservice;
import util.Page;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by dell on 2019/2/20.
 */
@Controller
@RequestMapping("/Invitation")
public class Invitationcontroller {
    @Resource
    public Invitationservice invitationservice;
@RequestMapping("all")
@ResponseBody
//条件查询加分页
    public  String  all(@RequestParam(value = "title") String title, @RequestParam(value = "pageIndex", required = false) Integer pageIndex, Model model){
    Page page = new Page();
    //条数
    int infoCount = invitationservice.Cont();
    //设置页面容量
    int pageSize = 4;
    page.setPageSize(pageSize);
    page.setTotalCount(infoCount);
    int currPageNo = 0;
    if (pageIndex == null) {
        pageIndex = 1;
    }
    currPageNo = (pageIndex - 1) * pageSize;
    page.setCurrPageNo(currPageNo);
    List<Invitation> list = new ArrayList<Invitation>();
    list = invitationservice.all(title,currPageNo, pageSize);
    HashMap<String, Object> appInfoMap = new HashMap<String, Object>();
    appInfoMap.put("list", list);
    appInfoMap.put("pages", page);
    System.out.print(appInfoMap);
    model.addAttribute(appInfoMap);
    System.out.print(appInfoMap);
    return JSON.toJSONString(appInfoMap);
}
}
